package org.dromara.comm_lhz.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.AllArgsConstructor;
import org.dromara.comm_lhz.entity.AsAuthenticationInformationEntity;
import org.dromara.comm_lhz.service.AsAuthenticationInformationHService;
import org.dromara.comm_lhz.util.Result;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.springframework.web.bind.annotation.*;

/**
 * 认证信息管理控制器
 * 提供认证信息的 CRUD 操作接口
 */
@RestController
@RequestMapping("/authenticationInformation")
@AllArgsConstructor
public class AsAuthenticationInformationHController {

    private final AsAuthenticationInformationHService asAuthenticationInformationHService;

    /**
     * 分页查询认证信息
     *
     * @param pageQuery 分页查询参数，包括页码和每页大小
     * @return 分页对象，包含认证信息实体的列表
     */
    @GetMapping("/selAuthentication")
    public Result<Page<AsAuthenticationInformationEntity>> selAuthentication(PageQuery pageQuery) {
        Page<AsAuthenticationInformationEntity> page = asAuthenticationInformationHService.selAuthentication(pageQuery);
        return Result.success("查询成功",page);
    }

    /**
     * 根据ID更新认证信息
     *
     * @param asAuthenticationInformationEntity 包含更新数据的认证信息实体
     * @return 更新操作结果，成功或失败的消息
     */
    @PostMapping("/updateAuthenticationById")
    public Result updateAuthenticationById(@RequestBody AsAuthenticationInformationEntity asAuthenticationInformationEntity) {
        boolean isUpdated = asAuthenticationInformationHService.updateAuthenticationById(asAuthenticationInformationEntity) > 0;
        if (isUpdated) {
            return Result.success("修改成功");
        } else {
            return Result.error("修改失败");
        }
    }

    /**
     * 根据ID删除认证信息
     *
     * @param id 需要删除的认证信息的ID
     * @return 删除操作结果，成功或失败的消息
     */
    @DeleteMapping("/delAuthenticationById/{id}")
    public Result delAuthenticationById(@PathVariable Long id) {
        boolean isRemoved = asAuthenticationInformationHService.removeById(id);
        if (isRemoved) {
            return Result.success("删除成功");
        } else {
            return Result.error("删除失败");
        }
    }

    /**
     * 添加新的认证信息
     *
     * @param asAuthenticationInformationEntity 要保存的认证信息实体
     * @return 添加操作结果，成功或失败的消息
     */
    @PostMapping("/saveAuthentication")
    public Result saveAuthentication(@RequestBody AsAuthenticationInformationEntity asAuthenticationInformationEntity) {
        boolean isSaved = asAuthenticationInformationHService.saveAuthentication(asAuthenticationInformationEntity) > 0;
        if (isSaved) {
            return Result.success("保存成功");
        } else {
            return Result.error("保存失败");
        }
    }
}
